﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 剧情设计器2._0
{
    [Serializable]
    public class Node
    {
        //节点的名称
        public string name = "";
        //节点中包含的剧情列表
        public List<Plot> plots = new List<Plot>();
        //节点的开始时间
        public int start_time = 0;
        //燃值
        public int hotvalue = 0;
        public override int GetHashCode()
        {
            int code = name.GetHashCode();
            if (start_time != 0) code += start_time.GetHashCode();
            foreach (Plot plot in plots)
                code += plot.GetHashCode();
            return code;
        }

        public int getTime()
        {
            int time = 0;
            foreach(Plot plot in plots)
            {
                int temp = plot.getTime();
                if (temp > time) time = temp;
            }
            return time;
        }

        public void draw(Graphics g, int x, int y)
        {
            int w;
            int h;
            int max_len = 0;
            int textHeight = 10;
            Pen pen = new Pen(Color.OrangeRed);
            for(int i = 0; i < plots.Count; i++)
            {
                if (plots[i].getW() > max_len) max_len = plots[i].getW();
            }
            w = max_len + 2;
            h = 18 + (88 + 2) * plots.Count;
            g.DrawRectangle(pen, x, y, w, h);
            g.DrawString(name, new Font("微软雅黑", textHeight), pen.Brush, new PointF(x + 2, y));
            for(int i = 0; i < plots.Count; i++)
            {
                plots[i].draw(g, x + 2 + plots[i].time_offset * (112 + 6), y + 18 + i * (88 + 2));
            }
        }


        public int getW()
        {
            int w, max_len = 0;
            for (int i = 0; i < plots.Count; i++)
            {
                if (plots[i].getW() > max_len) max_len = plots[i].getW();
            }
            w = max_len + 2;
            return w;
        }
    }
}